package com.pudding.aiservicedemo;

import com.pudding.tools.ModelUtil;
import dev.langchain4j.model.chat.ChatLanguageModel;
import dev.langchain4j.model.openai.OpenAiChatModel;
import dev.langchain4j.service.AiServices;
import dev.langchain4j.service.SystemMessage;
import dev.langchain4j.service.UserMessage;
import dev.langchain4j.service.V;

public class AiWriter {

    interface Writer {
        @SystemMessage("你是⼀名作家，根据输⼊的题⽬写⼀篇200字以内的作⽂")
        String write(String context);
    }

    interface Writer2 {
        @SystemMessage("你是⼀名作家，写⼀篇作⽂，题⽬是{{title}},字数不超过{{count}}个字")
        String write(@UserMessage String message, @V("title") String title, @V("count") Long count);
    }

    public static void main(String[] args) {
        //构建模型，过程略
        ChatLanguageModel model = OpenAiChatModel.builder()
                .apiKey(ModelUtil.API_KEY_OPENAI)
                .build();

        // 创建第一种服务
        Writer writer = AiServices.create(Writer.class, model);
        String content = writer.write("我最感谢的⼈");
        System.out.println(content);

        // 创建第二种服务
        Writer2 writer2 = AiServices.create(Writer2.class, model);
        String content2 = writer2.write("写⼀篇作⽂", "最爱看的电影", 200L);
        System.out.println(content2);
    }
}